package com.wnxy.sdd.controller;

import com.wnxy.sdd.common.result.Result;
import com.wnxy.sdd.entity.Chapter;
import com.wnxy.sdd.model.vo.ChapterVo;
import com.wnxy.sdd.model.vo.CourseVo;
import com.wnxy.sdd.service.IChapterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Jet
 * @since 2023-06-21
 */
@RestController
@RequestMapping("/chapter")
public class ChapterController {
    private final IChapterService chapterService;
    public ChapterController(IChapterService chapterService) {
        this.chapterService = chapterService;
    }

    /**
     * 在chapter.vue页面中,根据课程id查询章节、视频列表
     */
    @GetMapping("/video/{courseId}")
    public Result findChapterAndVideo(@PathVariable("courseId")String courseId) {
        List<ChapterVo> list = chapterService.findChapterAndVideo(courseId);
        return Result.ok(list);
    }

    /**
     * 添加、修改
     */
    @PostMapping
    public Result saveOrUpdate(@RequestBody Chapter chapter){
        chapterService.saveOrUpdate(chapter);
        return Result.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") String id){
        chapterService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据id查询
     */
    @GetMapping("{id}")
    public Result findById(@PathVariable("id") String id){
        Chapter chapter = chapterService.getById(id);
        return Result.ok(chapter);
    }
}
